using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace DD.Data.SQL
{
    public static class StyleManager
    {
        public static DataSet GetStyles()
        {
            DataSet ds = new DataSet();

            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_GET_STYLES", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter da = new SqlDataAdapter(com);

            conn.Open();
            da.Fill(ds);
            conn.Close();
            return ds;

        }
        public static void AddStyle(string StyleName)
        {

            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_ADD_STYLE", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter name = new SqlParameter("@NAME", StyleName);
            name.Direction = ParameterDirection.Input;

            com.Parameters.Add(name);

            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();


        }
        public static void UpdateStyle(string StyleName, int SID)
        {
            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_UPDATE_STYLE_NAME", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter name = new SqlParameter("@NAME", StyleName);
            name.Direction = ParameterDirection.Input;
            com.Parameters.Add(name);

            SqlParameter StyleId = new SqlParameter("@SID", SID);
            StyleId.Direction = ParameterDirection.Input;
            com.Parameters.Add(StyleId);

            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();

            
            
            

        }
        public static int CountProductsStyleAssingedTo(int styleid)
        {
            SqlConnection conn = new SqlConnection();
            conn = DD.Data.SQL.DataManager.GetConnection();

            SqlCommand com = new SqlCommand("sp_DD_CHECK_ASSIGNED_STYLE", conn);
            com.CommandType = CommandType.StoredProcedure;

            SqlParameter param1 = new SqlParameter("@SID", styleid);
            param1.SqlDbType = SqlDbType.Int;

            SqlParameter param2 = new SqlParameter("@COUNT", SqlDbType.Int);
            param2.Direction = ParameterDirection.Output;

            com.Parameters.Add(param1);
            com.Parameters.Add(param2);

            conn.Open();
            com.ExecuteNonQuery();
            conn.Close();

            return (int)param2.Value;


        }
    }
}
